<?php

session_name("alfacm_session");
define('SESSION_EXPIRATION_TIME', 60*60*9); // 9 hours
ini_set("session.gc_maxlifetime",SESSION_EXPIRATION_TIME);
session_start();

include('settings.php');
include('global_settings.php');
include('constants.php');

// include & construct general base_obj.php
include(PATH_TO_GLOBAL_OBJECTS . 'base_obj.php');
$base_obj = new base_obj();

//include global objects
$objects = $base_obj->getAllObjects(PATH_TO_GLOBAL_OBJECTS);
foreach ($objects as $object) {
    include (PATH_TO_GLOBAL_OBJECTS . $object);
}

//include local objects
$objects = $base_obj->getAllObjects(PATH_TO_OBJECTS);
foreach ($objects as $object) {
    include (PATH_TO_OBJECTS . $object);
}

/*
if (isset($_SESSION['timeout'])){
    if((time() - $_SESSION['timeout']) > SESSION_EXPIRATION_LIMIT){  
        $user_obj = new user_obj();
        $user_obj->logout();
        header("Location: " . ROOT);
        exit;  
    } else {
        $_SESSION['timeout']=time();
    }
}
*/

$GLOBALS['errors'] = array();
$GLOBALS['errors_alert'] = array();

$GLOBALS['smarty_functions'] = array(
    'printError' => 'error_obj::smarty_printError',
    'getClientName' => 'client_obj::smarty_getClientName',
    'isAssignedClientToTechnic' => 'user_obj::smarty_isAssignedClientToTechnic',
);


$base_obj->smarty();

// set debug mode
if (isset($_GET['dmode']) && ($_GET['dmode'] == 1)) {
    $_SESSION['debug_mode'] = true;
}
if (isset($_GET['dmode']) && ($_GET['dmode'] == 0)) {
    $_SESSION['debug_mode'] = false;
}

$GLOBALS['input'] = 'index';
if (isset($_GET['input'])) {
    $GLOBALS['input'] = $_GET['input'];
}

if (!isset($_SESSION['user']) || empty($_SESSION['user'])) {
    $user_obj = new user_obj();
    $_SESSION['user']['user_id'] = 0;
    $_SESSION['user']['user_type_id'] = 0;
    $_SESSION['user']['user_area_id'] = $user_obj->getUserArea($_SESSION['user']['user_type_id']);
}

base_obj::debug("REQUEST", $_REQUEST);
base_obj::debug("SESSION >> ". session_name(), $_SESSION);

?>
